﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;
using Jumpton.Data;
using System.Data;

namespace Jumpton.SFA.Server.BusinessRule.MasterData
{
    public class CustomerContactManager : BusinessLogic
    {
        public bool Save(CUSTOMER_CONTACTS contact)
        {
            bool Successful = false;
            //if (this.Load(channel.CODE, (int)channel.DOMAINID) != null)
            //{
            //    throw new Exception("代码已使用");
            //}
            if (contact != null)
            {
                try
                {
                    contact.Save();
                    Successful = true;
                }
                catch (Exception err)
                {
                    message = err.Message; throw err;
                    
                }
            }

            return Successful;
        }

        public static DataSet GetContactByCustomerID(int customerID)
        {
            return SqlData.OpenSP("usp_SelectCUSTOMER_CONTACTSsByCUSTOMER_ID", customerID);
        }

        public bool Delete(BANNERS banner)
        {
            bool Successful = false;
            if (banner != null)
            {
                try
                {
                    banner.Delete();
                    Successful = true;
                }
                catch (Exception err)
                {
                    message = err.Message; throw err;
                    
                }
            }

            return Successful;
        }

        /// <summary>
        /// 获取客户相关信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public DataTable GetCustomerInfo(string ID)
        {
            string strSQL = string.Format(@"select C.name,CI.telephone,CI.FAX,C.name2,CI.address_line,R.name as regoinName,
                    C.identity1,C.identity2,C.code, CT.name as CustomerType,CC.name as chainName,
                    CI.e_mail, case when CI.Gender=0 then '女' when CI.Gender=1 then '男' else '未知' end as Sex,
                    CL.name as customerLevel
                    from customers C 
                    inner join contact_info CI on C.ID=CI.customer_id
                    left join region R on R.ID=CI.city
                    left join dictionaryitems CT on CT.dictionaryItemID=C.cust_class_code
                    left join dictionaryitems CC on CC.dictionaryItemID=C.chain_code
                    left join dictionaryitems CL on CL.dictionaryItemID=C.bracket_id where C.ID='{0}'", ID);
            return SqlData.OpenSql(strSQL).Tables[0];
        }




      

       

       

   

       
    }
}
